/*
 * 操作日志
 */
define(function(require, exports, module) {
    require("common/umei.dev");
    // var page = require("common/umei.pagination");
    // var umei = require("common/umei.form");
    // var ajax = require("common/umei.ajax");
    require("My97DatePicker/WdatePicker");
    umei.url = {
	loadOpLogList : "loadOpLogList.do", loadLoginLogList : "loadLoginLogList.do", delRole : "delRole.do"
    }
    umei.searchParam = "";
    var url = umei.url.loadOpLogList;
    if (umei.type == "1") {
	url = umei.url.loadLoginLogList;
    }
    $("#selectAllbtn").click(function() {
	if ($(this).is(":checked")) {
	    $("#pager_content tr td input[name='chkall']").prop("checked", true);
	} else {
	    $("#pager_content tr td input[name='chkall']").prop("checked", false);
	}
    });

    $("#del-btn").click(function() {
	var checkInputs = $("#pager_content tr td input[name='chkall']:checked");
	var idsArray = [];
	for (var i = 0, _len = checkInputs.length; i < _len; i++) {
	    idsArray.push(checkInputs.eq(i).val());
	}
	if (idsArray.length == 0) {
	    umei_dialog.tipMsg({
		type : "warn", content : "请选择要删除的选项", timeout : 3000
	    });
	    return;
	}
	umei_dialog.confirm("确定要删除吗？", function() {
	    var data = {
		ids : idsArray.join(",")
	    }
	    ajax.postRequest({
		async : true, url : umei.url.delRole, data : data, fun : function(response) {
		    $("#pager_content tr td input[name='chkall']:checked").each(function() {
			$(this).parent().parent().parent().remove()
		    });
		    umei_dialog.tipMsg({
			type : "success", content : "删除成功", timeout : 1500
		    });
		}
	    });
	});
    });

    $("#searchBtn").click(function() {
	var startDate = $("#_calender1").val();
	var endDate = $("#_calender2").val();
	fillContent(1, startDate, endDate);
    });

    initPage(1);

    // 搜索
    umei.initForm({
	formObj : $("#searchform"), autocommit : "true", commiturl : url, fun : function(response) {
	    umei.searchParam = umei.serialize($("#searchform"));
	    fillPage(response);
	}
    });
    // 初始化页面
    function initPage(pageNo) {
	var data = umei.searchParam + "&pageNo=" + pageNo;
	umei.postRequest({
	    async : true, url : url, data : data, fun : function(response) {
		fillPage(response);
	    }
	});
    }

    function fillPage(response) {
	var data = response.data;
	var simplePage = data.page;
	var list = data.list;
	$("#pager_content tr:gt(0)").remove();
	if (list.length > 0) {
	    for (var i = 0, _len = list.length, d; i < _len, d = list[i]; i++) {
		$('<tr><td>' + d.userName + '</td><td>' + d.opObject + '</a></td><td>' + d.opDescription + '</td><td>' + d.opResult.description + '</td><td>' + d.createTime + '</td></tr>').appendTo(
			$("#pager_content"));
	    }
	} else {
	    $('<tr><td colspan=100 class="nodata">没有数据</td></tr>').appendTo($("#pager_content"));
	}
	umei.pagination({
	    pagePanelId : "pager", pageObj : simplePage, fun : initPage
	});
    }
});
